package androidx.fragment.app;

import android.annotation.SuppressLint;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;

public class c extends Fragment implements DialogInterface.OnCancelListener, DialogInterface.OnDismissListener {

    /* renamed from: b  reason: collision with root package name */
    private Handler f594b;

    /* renamed from: c  reason: collision with root package name */
    private Runnable f595c = new a();

    /* renamed from: d  reason: collision with root package name */
    private DialogInterface.OnCancelListener f596d = new b();
    /* access modifiers changed from: private */
    public DialogInterface.OnDismissListener e = new C0016c();
    private int f = 0;
    private int g = 0;
    private boolean h = true;
    private boolean i = true;
    private int j = -1;
    private boolean k;
    /* access modifiers changed from: private */
    public Dialog l;
    private boolean m;
    private boolean n;
    private boolean o;

    class a implements Runnable {
        a() {
        }

        @SuppressLint({"SyntheticAccessor"})
        public void run() {
            c.this.e.onDismiss(c.this.l);
        }
    }

    class b implements DialogInterface.OnCancelListener {
        b() {
        }

        @SuppressLint({"SyntheticAccessor"})
        public void onCancel(DialogInterface dialogInterface) {
            if (c.this.l != null) {
                c cVar = c.this;
                cVar.onCancel(cVar.l);
            }
        }
    }

    /* renamed from: androidx.fragment.app.c$c  reason: collision with other inner class name */
    class C0016c implements DialogInterface.OnDismissListener {
        C0016c() {
        }

        @SuppressLint({"SyntheticAccessor"})
        public void onDismiss(DialogInterface dialogInterface) {
            if (c.this.l != null) {
                c cVar = c.this;
                cVar.onDismiss(cVar.l);
            }
        }
    }

    private void e(boolean z, boolean z2) {
        if (!this.n) {
            this.n = true;
            this.o = false;
            Dialog dialog = this.l;
            if (dialog != null) {
                dialog.setOnDismissListener((DialogInterface.OnDismissListener) null);
                this.l.dismiss();
                if (!z2) {
                    if (Looper.myLooper() == this.f594b.getLooper()) {
                        onDismiss(this.l);
                    } else {
                        this.f594b.post(this.f595c);
                    }
                }
            }
            this.m = true;
            if (this.j >= 0) {
                getParentFragmentManager().D0(this.j, 1);
                this.j = -1;
                return;
            }
            u i2 = getParentFragmentManager().i();
            i2.o(this);
            if (z) {
                i2.i();
            } else {
                i2.h();
            }
        }
    }

    public void d() {
        e(false, false);
    }

    public Dialog f() {
        return this.l;
    }

    public int g() {
        return this.g;
    }

    public Dialog h(Bundle bundle) {
        return new Dialog(requireContext(), g());
    }

    public final Dialog i() {
        Dialog f2 = f();
        if (f2 != null) {
            return f2;
        }
        throw new IllegalStateException("DialogFragment " + this + " does not have a Dialog.");
    }

    public void j(Dialog dialog, int i2) {
        if (!(i2 == 1 || i2 == 2)) {
            if (i2 == 3) {
                Window window = dialog.getWindow();
                if (window != null) {
                    window.addFlags(24);
                }
            } else {
                return;
            }
        }
        dialog.requestWindowFeature(1);
    }

    public void k(m mVar, String str) {
        this.n = false;
        this.o = true;
        u i2 = mVar.i();
        i2.d(this, str);
        i2.h();
    }

    public void onActivityCreated(Bundle bundle) {
        Bundle bundle2;
        super.onActivityCreated(bundle);
        if (this.i) {
            View view = getView();
            if (this.l != null) {
                if (view != null) {
                    if (view.getParent() == null) {
                        this.l.setContentView(view);
                    } else {
                        throw new IllegalStateException("DialogFragment can not be attached to a container view");
                    }
                }
                d activity = getActivity();
                if (activity != null) {
                    this.l.setOwnerActivity(activity);
                }
                this.l.setCancelable(this.h);
                this.l.setOnCancelListener(this.f596d);
                this.l.setOnDismissListener(this.e);
                if (bundle != null && (bundle2 = bundle.getBundle("android:savedDialogState")) != null) {
                    this.l.onRestoreInstanceState(bundle2);
                }
            }
        }
    }

    public void onAttach(Context context) {
        super.onAttach(context);
        if (!this.o) {
            this.n = false;
        }
    }

    public void onCancel(DialogInterface dialogInterface) {
    }

    public void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        this.f594b = new Handler();
        this.i = this.mContainerId == 0;
        if (bundle != null) {
            this.f = bundle.getInt("android:style", 0);
            this.g = bundle.getInt("android:theme", 0);
            this.h = bundle.getBoolean("android:cancelable", true);
            this.i = bundle.getBoolean("android:showsDialog", this.i);
            this.j = bundle.getInt("android:backStackId", -1);
        }
    }

    public void onDestroyView() {
        super.onDestroyView();
        Dialog dialog = this.l;
        if (dialog != null) {
            this.m = true;
            dialog.setOnDismissListener((DialogInterface.OnDismissListener) null);
            this.l.dismiss();
            if (!this.n) {
                onDismiss(this.l);
            }
            this.l = null;
        }
    }

    public void onDetach() {
        super.onDetach();
        if (!this.o && !this.n) {
            this.n = true;
        }
    }

    public void onDismiss(DialogInterface dialogInterface) {
        if (!this.m) {
            e(true, true);
        }
    }

    /* JADX INFO: finally extract failed */
    public LayoutInflater onGetLayoutInflater(Bundle bundle) {
        LayoutInflater onGetLayoutInflater = super.onGetLayoutInflater(bundle);
        if (!this.i || this.k) {
            return onGetLayoutInflater;
        }
        try {
            this.k = true;
            Dialog h2 = h(bundle);
            this.l = h2;
            j(h2, this.f);
            this.k = false;
            return onGetLayoutInflater.cloneInContext(i().getContext());
        } catch (Throwable th) {
            this.k = false;
            throw th;
        }
    }

    public void onSaveInstanceState(Bundle bundle) {
        super.onSaveInstanceState(bundle);
        Dialog dialog = this.l;
        if (dialog != null) {
            bundle.putBundle("android:savedDialogState", dialog.onSaveInstanceState());
        }
        int i2 = this.f;
        if (i2 != 0) {
            bundle.putInt("android:style", i2);
        }
        int i3 = this.g;
        if (i3 != 0) {
            bundle.putInt("android:theme", i3);
        }
        boolean z = this.h;
        if (!z) {
            bundle.putBoolean("android:cancelable", z);
        }
        boolean z2 = this.i;
        if (!z2) {
            bundle.putBoolean("android:showsDialog", z2);
        }
        int i4 = this.j;
        if (i4 != -1) {
            bundle.putInt("android:backStackId", i4);
        }
    }

    public void onStart() {
        super.onStart();
        Dialog dialog = this.l;
        if (dialog != null) {
            this.m = false;
            dialog.show();
        }
    }

    public void onStop() {
        super.onStop();
        Dialog dialog = this.l;
        if (dialog != null) {
            dialog.hide();
        }
    }
}
